package com.project.service.gradeService.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.UserBean;
import com.project.mapper.gradeMapper.IUserMapper;
import com.project.service.gradeService.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl implements IUserService {
    @Autowired
    private IUserMapper userMapper;
    @Override
    public UserBean login(String userName, String pwd) {
        return userMapper.login(userName, pwd);
    }

    @Override
    public void updatePwd(int id, String newPwd) {
        userMapper.updatePwd(id, newPwd);
    }

    @Override
    public PageInfo<UserBean> findByName(int pageNO, String userName) {
        PageHelper.startPage(pageNO,PAGESIZE);
        PageInfo<UserBean> pageInfo = PageInfo.of(userMapper.findByName(userName));
        return pageInfo;
    }

    @Override
    public void add(UserBean userBean, int[] roleId) {
        userMapper.add(userBean);
        userMapper.addRoleList(userBean.getId(), roleId);
    }

    @Override
    public void del(int id) {
        userMapper.delUserRole(id);
        userMapper.del(id);
    }

    @Override
    public UserBean findById(int id) {
        return userMapper.findById(id);
    }

    @Override
    public void updateRole(int id,int[] roleId) {
        userMapper.delUserRole(id);
        userMapper.addRoleList(id, roleId);
    }
}
